Imports DevExpress.XtraTab
Imports DevExpress.XtraBars.Docking

Public Class UcnTabControl
    'represents UcnDiagramCanvasAdvanced in tabs

#Region "Attributes"
#Region "Private attributes"
    Private MbReadyForUse As Boolean = False 'indicates proper initialization of usercontrol
#End Region
#End Region
#Region "Constructors & Init"
    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.


        '**********************************************************************
        InitControl()
        '**********************************************************************
    End Sub
    'setting usercontrol settings before its using
    Private Function InitControl() As GeActionResult
        SetReadyForUse(False) 'disabling usercontrol
        Try
            SetReadyForUse(True) 'enabling usercontrol
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#Region "Properties"
#Region "Public properties"
    Public ReadOnly Property ReadyForUse() As Boolean
        Get
            Return MbReadyForUse
        End Get
    End Property
    'gets number of tabs
    Public ReadOnly Property NumberOfTabs() As Integer
        Get
            Return tcTabControl.TabPages.Count
        End Get
    End Property
    'gets Main tab page
    Public ReadOnly Property MainTabPage() As ClsUcnTabPage
        Get
            Return tcTabControl.TabPages(0)
        End Get
    End Property
#End Region
#End Region
#Region "Events handler"
#Region "tcTabControl - Events handler"
    'close button clicked
    Private Sub tcTabControl_CloseButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tcTabControl.CloseButtonClick
        Dim LoClosePageButtonEventArgs As ViewInfo.ClosePageButtonEventArgs = CType(e, ViewInfo.ClosePageButtonEventArgs)
        Dim LoTabPage As ClsUcnTabPage = LoClosePageButtonEventArgs.Page

        CloseTab(LoTabPage)
    End Sub
    'tab was clicked - close if it was tab header and middle button
    Private Sub tcTabControl_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tcTabControl.MouseClick
        If e.Button = Windows.Forms.MouseButtons.Middle Then
            Dim LoXtraTabHitInfo As ViewInfo.XtraTabHitInfo = tcTabControl.CalcHitInfo(tcTabControl.PointToClient(Cursor.Position))
            If LoXtraTabHitInfo.HitTest = ViewInfo.XtraTabHitTest.PageHeader Then
                Dim LoTabPage As ClsUcnTabPage = LoXtraTabHitInfo.Page
                CloseTab(LoTabPage)
            End If
        End If
    End Sub
    'tab was double clicked- close if it was tab header
    Private Sub tcTabControl_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tcTabControl.MouseDoubleClick
        Dim LoXtraTabHitInfo As ViewInfo.XtraTabHitInfo = tcTabControl.CalcHitInfo(tcTabControl.PointToClient(Cursor.Position))
        If LoXtraTabHitInfo.HitTest = ViewInfo.XtraTabHitTest.PageHeader Then
            Dim LoTabPage As ClsUcnTabPage = LoXtraTabHitInfo.Page
            CloseTab(LoTabPage)
        End If
    End Sub
    'selected tab was changed - hiding and showing dock panels
    Private Sub tcTabControl_SelectedPageChanged(ByVal sender As Object, ByVal e As DevExpress.XtraTab.TabPageChangedEventArgs) Handles tcTabControl.SelectedPageChanged
        Dim LoPreviousTab As ClsUcnTabPage = e.PrevPage
        Dim LoCurrentTab As ClsUcnTabPage = e.Page

        'hide all visible floated panels
        If LoPreviousTab IsNot Nothing Then
            Select Case LoPreviousTab.TypeOfTab
                Case GeTypeOfTab.kkMainTab, GeTypeOfTab.kkClassDiagramTab
                    For Each LoDockPanel As DockPanel In LoPreviousTab.ucnDiagramCanvasAdvanced.xtrDockManager.Panels
                        If LoDockPanel.Dock = DockingStyle.Float AndAlso LoDockPanel.Visibility = DockVisibility.Visible Then LoDockPanel.Hide()
                    Next
                Case GeTypeOfTab.kkVersionComparisonTab
                    For Each LoDockPanel As DockPanel In LoPreviousTab.LeftCanvasAdvanced.xtrDockManager.Panels
                        If LoDockPanel.Dock = DockingStyle.Float AndAlso LoDockPanel.Visibility = DockVisibility.Visible Then LoDockPanel.Hide()
                    Next

                    For Each LoDockPanel As DockPanel In LoPreviousTab.RightCanvasAdvanced.xtrDockManager.Panels
                        If LoDockPanel.Dock = DockingStyle.Float AndAlso LoDockPanel.Visibility = DockVisibility.Visible Then LoDockPanel.Hide()
                    Next
            End Select
        End If

        'show all hidden panels
        Select Case LoCurrentTab.TypeOfTab
            Case GeTypeOfTab.kkMainTab, GeTypeOfTab.kkClassDiagramTab
                'For Each LoDockPanel As DockPanel In LoCurrentTab.ucnDiagramCanvasAdvanced.xtrDockManager.Panels
                '    If LoDockPanel.Visibility = DockVisibility.Hidden Then LoDockPanel.Show()
                'Next
            Case GeTypeOfTab.kkVersionComparisonTab
                For Each LoDockPanel As DockPanel In LoCurrentTab.LeftCanvasAdvanced.xtrDockManager.Panels
                    If LoDockPanel.Dock = DockingStyle.Float AndAlso LoDockPanel.Visibility = DockVisibility.Visible Then LoDockPanel.Hide()
                Next

                For Each LoDockPanel As DockPanel In LoCurrentTab.RightCanvasAdvanced.xtrDockManager.Panels
                    If LoDockPanel.Dock = DockingStyle.Float AndAlso LoDockPanel.Visibility = DockVisibility.Visible Then LoDockPanel.Hide()
                Next
        End Select

        'merge ribbon menu
        MergeRibbonMenuOfTab(LoCurrentTab)
        'switch application button icon of ribbon menu
        SwitchApplicationButtonIconOfRibbonMenu(LoCurrentTab)
        'switches toolbar buttons of ribbon menu
        SwitchToolbarButtonsOfRibbonMenu(LoCurrentTab)
    End Sub
#End Region
#End Region
#Region "Functions"
#Region "Manipulating with tabs"
    'creating a tab of specified type with no components
    Private Function CreateVirginTab(ByVal IeTypeOfTab As GeTypeOfTab) As ClsUcnTabPage
        Try
            'creating a new tab
            Return New ClsUcnTabPage(IeTypeOfTab, Me)
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'creating a tab of specified type with components
    Private Function CreateTab(ByVal IeTypeOfTab As GeTypeOfTab) As ClsUcnTabPage
        Try
            'creating a new tab
            Dim LoTab As ClsUcnTabPage = CreateVirginTab(IeTypeOfTab)

            Select Case IeTypeOfTab
                Case GeTypeOfTab.kkMainTab
                    LoTab.Appearance.Header.Font = New System.Drawing.Font("Tahoma", 9.0F, System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic)
                    LoTab.Appearance.Header.ForeColor = Color.Black
                    LoTab.Image = imlTabPage16x16.Images("SOLUTION")
                Case GeTypeOfTab.kkClassDiagramTab
                    LoTab.Appearance.Header.Font = New System.Drawing.Font("Tahoma", 8.0F, System.Drawing.FontStyle.Bold)
                    LoTab.Appearance.Header.ForeColor = Color.Blue
                    LoTab.Image = imlTabPage16x16.Images("MODULE")
                Case GeTypeOfTab.kkVersionComparisonTab
                    LoTab.Appearance.Header.Font = New System.Drawing.Font("Tahoma", 8.0F, System.Drawing.FontStyle.Bold)
                    LoTab.Appearance.Header.ForeColor = Color.Black
                    LoTab.Image = imlTabPage16x16.Images("COMPAREVERSIONS")
                Case GeTypeOfTab.kkUseCaseTab
                    LoTab.Appearance.Header.Font = New System.Drawing.Font("Tahoma", 8.0F, System.Drawing.FontStyle.Bold)
                    LoTab.Appearance.Header.ForeColor = Color.Green
                    LoTab.Image = imlTabPage16x16.Images("USECASEDIAGRAM")
            End Select
            LoTab.ShowCloseButton = DevExpress.Utils.DefaultBoolean.True
            LoTab.Appearance.Header.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center
            LoTab.Appearance.Header.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center
            LoTab.Text = ""
            LoTab.Appearance.Header.TextOptions.Trimming = DevExpress.Utils.Trimming.EllipsisPath

            'creating a new canvas
            Select Case IeTypeOfTab
                Case GeTypeOfTab.kkMainTab, GeTypeOfTab.kkClassDiagramTab, GeTypeOfTab.kkUseCaseTab
                    Dim LoDiagramCanvasAdvanced As UcnDiagramCanvasAdvanced = New UcnDiagramCanvasAdvanced
                    LoDiagramCanvasAdvanced.Dock = DockStyle.Fill

                    'adding advanced canvas to tab
                    LoTab.AddCanvasToControlsCollection(LoDiagramCanvasAdvanced)
                Case GeTypeOfTab.kkVersionComparisonTab
                    'creating left and right UcnDiagramCanvasAdvanced 
                    Dim LoLeftDiagramCanvasAdvanced As UcnDiagramCanvasAdvanced = New UcnDiagramCanvasAdvanced
                    LoLeftDiagramCanvasAdvanced.Dock = DockStyle.Fill
                    Dim LoRightDiagramCanvasAdvanced As UcnDiagramCanvasAdvanced = New UcnDiagramCanvasAdvanced
                    LoRightDiagramCanvasAdvanced.Dock = DockStyle.Fill
                    'adding split control to tab
                    Dim LoSplitContainerControl As DevExpress.XtraEditors.SplitContainerControl = New DevExpress.XtraEditors.SplitContainerControl
                    LoSplitContainerControl.SplitterPosition = Width / 2
                    LoSplitContainerControl.Dock = DockStyle.Fill
                    LoSplitContainerControl.Panel1.Controls.Add(LoLeftDiagramCanvasAdvanced)
                    LoTab.LeftCanvasAdvanced = LoLeftDiagramCanvasAdvanced
                    LoSplitContainerControl.Panel2.Controls.Add(LoRightDiagramCanvasAdvanced)
                    LoTab.RightCanvasAdvanced = LoRightDiagramCanvasAdvanced

                    'adding split control to tab
                    LoTab.AddSplitControlToControlsCollection(LoSplitContainerControl)
            End Select

            Return LoTab
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'insert a tab at the specified position
    Private Function InsertTab(ByVal IoTabPage As ClsUcnTabPage, ByVal IiPosition As Integer) As GeActionResult
        Try
            tcTabControl.TabPages.Insert(IiPosition, IoTabPage)
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'gets class diagram tab by path to aMod file and version VID
    Public Function GetTabClassDiagram(ByVal IsPath As String, ByVal IiVID As Integer) As ClsUcnTabPage
        Try
            Dim LoTab As ClsUcnTabPage = Nothing
            For Each LoTabPage As ClsUcnTabPage In tcTabControl.TabPages
                If LoTabPage.TypeOfTab = GeTypeOfTab.kkClassDiagramTab AndAlso LoTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.AmodFilePath = IsPath AndAlso LoTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.AmodVersion.GetVersionVID = IiVID Then
                    LoTab = LoTabPage
                    Exit For
                End If
            Next

            Return LoTab
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'gets tab with compared two versions by path to aMod and versions of two compared versions 
    Public Function GetTabComparedVersions(ByVal IsPath As String, ByVal IiLeftVID As Integer, ByVal IiRightVID As Integer) As ClsUcnTabPage
        Try
            Dim LoTab As ClsUcnTabPage = Nothing
            For Each LoTabPage As ClsUcnTabPage In tcTabControl.TabPages
                If LoTabPage.TypeOfTab = GeTypeOfTab.kkVersionComparisonTab AndAlso LoTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.AmodFilePath = IsPath AndAlso LoTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.AmodVersion.GetVersionVID = IiLeftVID AndAlso LoTabPage.RightCanvasAdvanced.ucnDiagramCanvasBaseUC.AmodVersion.GetVersionVID = IiRightVID Then
                    LoTab = LoTabPage
                    Exit For
                End If
            Next

            Return LoTab
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'gets all tabs with compared two versions by path to aMod
    Public Function GetAllTabsComparedVersionsByAmodPath(ByVal IsPath As String) As Collection
        Dim LoTabs As Collection = New Collection
        Try
            For Each LoTabPage As ClsUcnTabPage In tcTabControl.TabPages
                If LoTabPage.TypeOfTab = GeTypeOfTab.kkVersionComparisonTab AndAlso LoTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.AmodFilePath = IsPath Then
                    LoTabs.Add(LoTabPage)
                End If
            Next

            Return LoTabs
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return LoTabs
        End Try
    End Function
    'gets use case diagram tab by path to aMod
    Public Function GetTabUCD(ByVal IsPath As String) As ClsUcnTabPage
        Try
            Dim LoTab As ClsUcnTabPage = Nothing
            For Each LoTabPage As ClsUcnTabPage In tcTabControl.TabPages
                If LoTabPage.TypeOfTab = GeTypeOfTab.kkUseCaseTab AndAlso LoTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.AmodFilePath = IsPath Then
                    LoTab = LoTabPage
                    Exit For
                End If
            Next

            Return LoTab
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'gets tab by its index
    Public Function GetTabByIndex(ByVal IiIndex As Integer) As ClsUcnTabPage
        Try
            Return tcTabControl.TabPages(IiIndex)
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'focuses a tab based on ClsTabPage object
    Public Function FocusTab(ByVal IoTabPage As ClsUcnTabPage) As GeActionResult
        Try
            'tab can be selected only if tab is not nothing and is in tabs collection
            If IoTabPage IsNot Nothing AndAlso tcTabControl.TabPages.IndexOf(IoTabPage) <> -1 Then
                tcTabControl.SelectedTabPage = IoTabPage
            Else
                Throw New Exception
            End If

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'focuses a tab based on order of tab
    Public Function FocusTab(ByVal IiIndex As Integer) As GeActionResult
        Try
            If IiIndex >= 0 AndAlso IiIndex <= tcTabControl.TabPages.Count - 1 Then
                If tcTabControl.SelectedTabPageIndex <> IiIndex Then
                    tcTabControl.SelectedTabPageIndex = IiIndex
                End If
            Else
                Throw New Exception
            End If

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'add a new tab of specified type at the specified position
    Public Function AddTab(ByVal IeTypeOfTab As GeTypeOfTab, ByVal IiPosition As Integer) As ClsUcnTabPage
        Try
            Dim LoTab As ClsUcnTabPage = CreateTab(IeTypeOfTab)
            If InsertTab(LoTab, IiPosition) <> GeActionResult.kkOk Then Throw New Exception

            Return LoTab
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return Nothing
        End Try
    End Function
    'removes a specified tab
    Public Function RemoveTab(ByVal IoTab As ClsUcnTabPage) As GeActionResult
        Try
            tcTabControl.TabPages.Remove(IoTab)
            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'closes a specified tab
    Public Function CloseTab(ByVal IoTabPage As ClsUcnTabPage, Optional ByVal IbAskForClosingProject As Boolean = True) As GeActionResult
        Try
            Dim LoAction As ClsAction = New ClsAction(GeAction.kkCloseTab)
            LoAction.SetData(IbAskForClosingProject, "ASKFORCLOSINGPROJECT")
            Return IoTabPage.Execute(LoAction)
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#Region "Common functions"
    'merges ribbon menu of this tab = assign ribbon menu of UcnDiagramCanvasBase to frmMainForm's ribbon menu
    Public Function MergeRibbonMenuOfTab(ByVal IoUcnTabPage As ClsUcnTabPage) As GeActionResult
        Try
            'child menu = ucnDiagramCanvasBaseUC ribbon menu
            'parent menu = frmMainForm ribbon menu

            If frmMainForm.RibbonControl.MergedRibbon IsNot Nothing Then
                'save current selected page to child menu
                frmMainForm.RibbonControl.MergedRibbon.SelectedPage = frmMainForm.RibbonControl.SelectedPage
                ' ''unmerge menu
                ' ''frmMainForm.RibbonControl.UnMergeRibbon()
            End If


            'frmMainForm.RibbonControl.UnMergeRibbon()

            Select Case IoUcnTabPage.TypeOfTab
                Case GeTypeOfTab.kkMainTab, GeTypeOfTab.kkClassDiagramTab, GeTypeOfTab.kkUseCaseTab
                    '-------------
                    'rpPermanent is only for ensuring not blinking effect during merging menu. rpPermanent is always in parent menu so hight of menu os still the same!
                    frmMainForm.rpPermanent.Visible = True
                    '-------------
                    'theres problem with inactivity of some buttons in parent menu so I need to call ForceInitialize (I found this solution on forum)
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl.ForceInitialize()
                    frmMainForm.RibbonControl.MergeRibbon(IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl)
                    '-------------
                    'rpPermanent is only for ensuring not blinking effect during merging menu. rpPermanent is always in parent menu so hight of menu os still the same!
                    frmMainForm.rpPermanent.Visible = False
                    '-------------
                    'restore last selected page of child menu to parent menu
                    frmMainForm.RibbonControl.SelectedPage = frmMainForm.RibbonControl.MergedPages(frmMainForm.RibbonControl.MergedRibbon.SelectedPage.Text)
                Case GeTypeOfTab.kkVersionComparisonTab
                    'take menu from left diagram
                    Dim LoLeftUcnDiagramCanvasAdvanced As UcnDiagramCanvasAdvanced = IoUcnTabPage.ucnDiagramCanvasAdvanced(GeSideOfCanvas.kkLeft)
                    'set default visibility of pages of left diagram- this is here coz at the end of this method only rpView page will be visible and theres problem when this tab lost focus and get it back, coz only that page is visible!
                    LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.SetAfterInit(False)
                    'make rpView of left diagram invisible so it will be not merged
                    LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.rpView.Visible = False
                    'merge left menu
                    '-------------
                    'rpPermanent is only for ensuring not blinking effect during merging menu. rpPermanent is always in parent menu so hight of menu os still the same!
                    frmMainForm.rpPermanent.Visible = True
                    '-------------
                    'theres problem with inactivity of some buttons in parent menu so I need to call ForceInitialize (I found this solution on forum)
                    LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl.ForceInitialize()
                    frmMainForm.RibbonControl.MergeRibbon(LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl)
                    '-------------
                    'rpPermanent is only for ensuring not blinking effect during merging menu. rpPermanent is always in parent menu so hight of menu os still the same!
                    frmMainForm.rpPermanent.Visible = False
                    '-------------
                    'make ONLY rpView page of left diagram in ucnDiagramCanvasBaseUC visible 
                    For Each LoRibbonPage As DevExpress.XtraBars.Ribbon.RibbonPage In LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl.Pages
                        If LoRibbonPage.Equals(LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.rpView) Then
                            LoRibbonPage.Visible = True
                        Else
                            LoRibbonPage.Visible = False
                        End If
                    Next

                    'make ribbon menu of left diagram in ucnDiagramCanvasBaseUC visible
                    LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl.Visible = True
                    'IoUcnDiagramCanvasBase.barBtnLayeredLayout.MergeType = DevExpress.XtraBars.BarMenuMerge.Remove

                    'hide toolbar of ribbon menu of left diagram in ucnDiagramCanvasBaseUC 
                    LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl.ToolbarLocation = DevExpress.XtraBars.Ribbon.RibbonQuickAccessToolbarLocation.Hidden

                    'make ONLY rpView page of right diagram in ucnDiagramCanvasBaseUC visible 
                    Dim LoRightUcnDiagramCanvasAdvanced As UcnDiagramCanvasAdvanced = IoUcnTabPage.ucnDiagramCanvasAdvanced(GeSideOfCanvas.kkRight)
                    For Each LoRibbonPage As DevExpress.XtraBars.Ribbon.RibbonPage In LoRightUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl.Pages
                        If LoRibbonPage.Equals(LoRightUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.rpView) Then
                            LoRibbonPage.Visible = True
                        Else
                            LoRibbonPage.Visible = False
                        End If
                    Next

                    'make ribbon menu of right diagram in ucnDiagramCanvasBaseUC visible
                    LoRightUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl.Visible = True
                    'hide toolbar of ribbon menu of right diagram in ucnDiagramCanvasBaseUC 
                    LoRightUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.xtrRibbonControl.ToolbarLocation = DevExpress.XtraBars.Ribbon.RibbonQuickAccessToolbarLocation.Hidden

                    '--------
                    'restore last selected page of child menu to parent menu
                    Dim LsRibbonSelectedPageText As String = frmMainForm.RibbonControl.MergedRibbon.SelectedPage.Text
                    'check if theres going to be selected rpView page in parent menu. Its not possible coz rpView is only in child menu.
                    If LsRibbonSelectedPageText = LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.rpView.Text Then LsRibbonSelectedPageText = LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.rpModule.Text
                    frmMainForm.RibbonControl.SelectedPage = frmMainForm.RibbonControl.MergedPages(LsRibbonSelectedPageText)
                    'selecte rpView page of child menu coz there was selected page which is not visible now (it was selected at the beginning of this sub)
                    frmMainForm.RibbonControl.MergedRibbon.SelectedPage = frmMainForm.RibbonControl.MergedRibbon.Pages(LoLeftUcnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.rpView.Text)
            End Select

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'switches icon of application button of ribbon menu
    Private Function SwitchApplicationButtonIconOfRibbonMenu(ByVal IoUcnTabPage As ClsUcnTabPage) As GeActionResult
        Try
            Select Case IoUcnTabPage.TypeOfTab
                Case GeTypeOfTab.kkMainTab
                    frmMainForm.RibbonControl.ApplicationIcon = frmMainForm.imlApplicationButtonImages.Images("SOLUTION")
                Case GeTypeOfTab.kkClassDiagramTab
                    frmMainForm.RibbonControl.ApplicationIcon = frmMainForm.imlApplicationButtonImages.Images("MODULE")
                Case GeTypeOfTab.kkUseCaseTab
                    frmMainForm.RibbonControl.ApplicationIcon = frmMainForm.imlApplicationButtonImages.Images("USECASE")
                Case GeTypeOfTab.kkVersionComparisonTab
                    frmMainForm.RibbonControl.ApplicationIcon = frmMainForm.imlApplicationButtonImages.Images("COMPAREVERSIONS")
            End Select

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    'switches toolbar buttons of ribbon menu
    Private Function SwitchToolbarButtonsOfRibbonMenu(ByVal IoUcnTabPage As ClsUcnTabPage) As GeActionResult
        Try
            Select Case IoUcnTabPage.TypeOfTab
                Case GeTypeOfTab.kkMainTab
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveUCDofModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseUCDdiagram.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnVersionsManagement.Visibility = DevExpress.XtraBars.BarItemVisibility.Never

                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveAll.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnNewSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnOpenSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                Case GeTypeOfTab.kkClassDiagramTab
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveUCDofModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseUCDdiagram.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnNewSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnOpenSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never

                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveAll.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnVersionsManagement.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                Case GeTypeOfTab.kkUseCaseTab
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnNewSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnOpenSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnVersionsManagement.Visibility = DevExpress.XtraBars.BarItemVisibility.Never

                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveAll.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveUCDofModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.ucnDiagramCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseUCDdiagram.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                Case GeTypeOfTab.kkVersionComparisonTab
                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveAll.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnSaveUCDofModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseUCDdiagram.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnNewSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnOpenSolution.Visibility = DevExpress.XtraBars.BarItemVisibility.Never

                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnCloseModule.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
                    IoUcnTabPage.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC.barBtnVersionsManagement.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
            End Select

            Return GeActionResult.kkOk
        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
#End Region
#End Region
#Region "Subs"
    'sets MbReadyForUse attribute and sets Enable property of usercontrol
    Private Sub SetReadyForUse(ByVal IbValue As Boolean)
        MbReadyForUse = IbValue
        Me.Enabled = IbValue 'enabling usercontrol
    End Sub
#End Region

    '#######################################
    'execute function
    Public Function Execute(ByRef OoAction As ClsAction) As GeActionResult
        Try
            Dim LeResult As GeActionResult = GeActionResult.kkOk
            '---------------------------------------------
            'ACTION BEFORE ACTION
            '---------------------------------------------
            '---------------------------------------------
            'ACTION
            '---------------------------------------------
            Select Case OoAction.Action
                Case GeAction.kkSetDesktopForFirstUsage
                    'initialization of usercontrol for the first usage (creating main tab and setting some default settings)
                    OoAction.SetData(GeTypeOfTab.kkMainTab, "TYPEOFTAB")
                    OoAction.SetData(0, "TABPOSITION")

                    OoAction.Action = GeAction.kkAddTab
                    LeResult = Execute(OoAction)
                    OoAction.Action = GeAction.kkSetDesktopForFirstUsage

                    'during starting application there was already merged ribbon menu of main tab, but menu was not set (enabled, visible etc)! So now merge ribbon menu again after menu was set.
                    frmMainForm.RibbonControl.UnMergeRibbon()
                    MergeRibbonMenuOfTab(OoAction.GetData("TABPAGE"))
                Case GeAction.kkAddTab
                    'adding a tab
                    Dim LoTab As ClsUcnTabPage = AddTab(OoAction.GetData("TYPEOFTAB"), OoAction.GetData("TABPOSITION"))
                    If LoTab IsNot Nothing Then
                        'initialization of a tab
                        OoAction.SetData(Me, "TABCONTROL")
                        OoAction.SetData(LoTab, "TABPAGE")
                        OoAction.SetData(MainTabPage, "MAINTABPAGE")

                        OoAction.Action = GeAction.kkInitTab
                        LeResult = LoTab.Execute(OoAction)
                        OoAction.Action = GeAction.kkAddTab
                    Else
                        LeResult = False
                    End If
                Case GeAction.kkaModSolutionOpenFile
                    LeResult = MainTabPage.Execute(OoAction)
                Case GeAction.kkaModTryToOpenVersions
                    OoAction.SetData(GeTypeOfTab.kkClassDiagramTab, "TYPEOFTAB")
                    OoAction.SetData(NumberOfTabs, "TABPOSITION")

                    OoAction.Action = GeAction.kkAddTab
                    LeResult = Execute(OoAction)
                    OoAction.Action = GeAction.kkaModTryToOpenVersions

                    If LeResult = GeActionResult.kkOk Then
                        Dim LoTab As ClsUcnTabPage = OoAction.GetData("TABPAGE")
                        OoAction.Action = GeAction.kkaModOpenVersion
                        LeResult = LoTab.Execute(OoAction)
                        OoAction.Action = GeAction.kkaModTryToOpenVersions

                        If LeResult = GeActionResult.kkOk Then FocusTab(LoTab)
                    End If
                Case GeAction.kkaModTryToOpenUCDofModule
                    OoAction.SetData(GeTypeOfTab.kkUseCaseTab, "TYPEOFTAB")
                    OoAction.SetData(NumberOfTabs, "TABPOSITION")

                    OoAction.Action = GeAction.kkAddTab
                    LeResult = Execute(OoAction)
                    OoAction.Action = GeAction.kkaModTryToOpenUCDofModule

                    If LeResult = GeActionResult.kkOk Then
                        Dim LoTab As ClsUcnTabPage = OoAction.GetData("TABPAGE")
                        OoAction.Action = GeAction.kkaModOpenUCDofModule
                        LeResult = LoTab.Execute(OoAction)
                        OoAction.Action = GeAction.kkaModTryToOpenUCDofModule

                        If LeResult = GeActionResult.kkOk Then FocusTab(LoTab)
                    End If
                Case GeAction.kkaModTryToCompareVersions
                    OoAction.SetData(GeTypeOfTab.kkVersionComparisonTab, "TYPEOFTAB")
                    OoAction.SetData(NumberOfTabs, "TABPOSITION")

                    OoAction.Action = GeAction.kkAddTab
                    LeResult = Execute(OoAction)
                    OoAction.Action = GeAction.kkaModTryToCompareVersions

                    If LeResult = GeActionResult.kkOk Then
                        Dim LoTab As ClsUcnTabPage = OoAction.GetData("TABPAGE")
                        Dim LiLeftVersion As Integer = OoAction.GetData("LEFTVERSION")
                        Dim LiRightVersion As Integer = OoAction.GetData("RIGHTVERSION")

                        OoAction.Action = GeAction.kkaModOpenVersion
                        OoAction.SetData(LiLeftVersion, "VERSION")
                        OoAction.SetData(True, "OPENEDVERSIONFORREADING")
                        OoAction.SetData(LoTab.RightCanvasAdvanced.ucnDiagramCanvasBaseUC, "RIGHTCANVASBASE")
                        OoAction.SetData(GeSideOfCanvas.kkLeft, "SIDEOFCANVASADVANCEDFOROPENVERSION")
                        LeResult = LoTab.Execute(OoAction)
                        OoAction.Action = GeAction.kkaModTryToCompareVersions

                        If LeResult = GeActionResult.kkOk Then
                            OoAction.Action = GeAction.kkaModOpenVersion
                            OoAction.SetData(LiRightVersion, "VERSION")
                            OoAction.SetData(True, "OPENEDVERSIONFORREADING")
                            OoAction.RemoveData("RIGHTCANVASBASE") 'remove right canvasbase so its not assigned to property on right canvas
                            OoAction.SetData(LoTab.LeftCanvasAdvanced.ucnDiagramCanvasBaseUC, "LEFTCANVASBASE")
                            OoAction.SetData(GeSideOfCanvas.kkRight, "SIDEOFCANVASADVANCEDFOROPENVERSION")
                            LeResult = LoTab.Execute(OoAction)
                            OoAction.Action = GeAction.kkaModTryToCompareVersions

                            'focus tab after also right canvas was initialized
                            If LeResult = GeActionResult.kkOk Then
                                FocusTab(LoTab)
                            End If
                        End If
                    End If
            End Select
            '---------------------------------------------
            'ACTION AFTER ACTION
            '---------------------------------------------
            Select Case OoAction.Action

            End Select
            '---------------------------------------------
            Return LeResult
            '---------------------------------------------

        Catch ex As Exception
            LogEventFromException(ex, , , )
            Return GeActionResult.kkError
        End Try
    End Function
    '#######################################

End Class